﻿
function showAuditorType(o){

    pop = window.createPopup();
    
    var html ="<table id='t1' border='0' cellspacing='0' style='font-family:宋体;font-size:12px;border:1 solid #C1D2DF;background-color:#FFFFFF;width:100%;'>";
    html += "<tr><td style='background-color:#AFE3F9;width:10px;'></td>";
    html += "<td align='left' style='padding-top: 2px;padding-left:3px;' action='selectInitiator'>发起人</td>";
    html += "</tr><tr>";
    html += "<td style='background-color:#AFE3F9;'></td>";
    html += "<td align='left' action='selectLast' style='padding-left:3px'>上一步骤责任人</td>";
    html += "</tr><tr>";
    html += "<td style='background-color:#AFE3F9;'></td>";
    html += "<td align='left' action='selectMore' style='padding-left:3px'>流程相关人</td>";
    html += "</tr></table>";
    
    pop.document.body.innerHTML = html;
    
    var rowObjs = pop.document.getElementsByTagName("tr");

    var rowCount = rowObjs.length;

    for(var i=0;i<rowObjs.length;i++)
    {     
        rowObjs[i].cells[1].onmouseover=function(){
            this.style.color = "#F72B29";
            this.style.cursor = "hand";
        }
        rowObjs[i].cells[1].onmouseout=function(){
            this.style.color = "#000000";
            this.style.cursor = "hand";
        }
        rowObjs[i].cells[1].onclick = function(){
            menuclick(this.action);
        }
    }
    
    pop.document.oncontextmenu=function()
    {
       return false;
    }
    
    pop.document.onclick=function()
    {
        pop.hide();
    }

    //修复IE8问题
    if (typeof (showPopup) == "function") {
        showPopup(pop, findPosX(o) - 87, findPosY(o) + 22, 107, rowCount * 17, document.body);
    }
    else {
        pop.show(findPosX(o) - 87, findPosY(o) + 22, 107, rowCount * 17, document.body);
        //pop.show(findPosX(o) - 87, findPosY(o) + 22, 107, pop.document.getElementById("t1").offsetHeight, document.body);
    }
    //pop.show(findPosX(o) - 87,findPosY(o) + 22,107,rowCount * 17,document.body);
    //修复IE8问题
    
    return true;
}

function menuclick(action){
    var processGUID = document.getElementById("__processGUID");
    var stepPathGUID = document.getElementById("__stepPathGUID");
    var returnString;
    switch(action){
        case "selectInitiator":            
            returnString = GetDataFromXMLHTTP("/MyWorkflow/WF_XmlHTTP.aspx","GetInitiator",processGUID.value,"","");
            if (returnString != undefined && returnString != "")
                setCC(returnString.split(",")[0],returnString.split(",")[1]);
            return;
        case "selectLast":
            if(stepPathGUID){
                returnString = GetDataFromXMLHTTP("/MyWorkflow/WF_XmlHTTP.aspx","GetLastAuditor",processGUID.value,stepPathGUID.value,"");
                if (returnString != undefined && returnString != ""){
                     var arr = returnString.split(";");
		            for(var i = arr.length -1 ; i >= 0 ; i--){
		                setCC(arr[i].split(",")[0],arr[i].split(",")[1]);
		            }
                }
            }
            return;
        case "selectMore":
            var sTitle, sURL, sParams, sArgs,iX, iY;
	        sTitle = "选择抄送人";
	        sURL = "/MyWorkflow/SelectProcessAuditors.aspx";
	        sArgs = "";
	        sParams = "processGUID=" + processGUID.value;
        	
	        iX = 430;
	        iY = 450;
        	
	        returnString = openMyDlg(sTitle,sURL,sParams,sArgs,iX,iY);

	        if (returnString != undefined && returnString != "")
	        {
		        var arr = returnString.split(";");
		        for(var i = arr.length -1 ; i >= 0 ; i--){
		            setCC(arr[i].split(",")[0],arr[i].split(",")[1]);
		        }
	        }
	        return;
     }
}

//设置抄送人
function setCC(name,guid){
    var CCUserName = document.getElementById("txtCCUserName");
    var CCUserGUID = document.getElementById("txtCCUserGUID");
    
    var reg = eval("/" + guid + "/gi");
    if(CCUserGUID.value.search(reg) != -1){
        return;
    }
    
    if(CCUserName.value!=""){
        CCUserName.value += ";"
    }
    
    CCUserName.value +=name;
    
    if(CCUserGUID.value!=""){
        CCUserGUID.value += ";"
    }
    
    CCUserGUID.value +=guid;
}

function findPosX(obj) {
	var curleft = 0;
	
	if (obj.offsetParent) { 
	   while (obj.offsetParent) {
	    curleft += obj.offsetLeft;
	    obj = obj.offsetParent;        
	   }
	} else if (obj.x) curleft += obj.x;
	return curleft;
}
function findPosY(obj) {
	var curtop = 0;
	
	if (obj.offsetParent) {
	   while (obj.offsetParent) {
	    curtop += obj.offsetTop;
	    obj = obj.offsetParent;
	   }
	} else if (obj.y) curtop += obj.y;
	return curtop;
}